//
//  ProductsTests.m
//  CodeKatas
//
//  Created by Viktor Lazarevich on 28-Feb-10.
//  Copyright 2010 Home. All rights reserved.
//

#import "ProductsTests.h"
#import "Product.h"
#import "SimplePricing.h"
#import "AdditionalFreeItemsPricing.h"


@implementation ProductsTests

// --- SetUp and TearDown methods --- //
- (void)setUp {
}
- (void)tearDown {
}


// --- Product tests --- //
- (void)testProductCreateEmpty {
	Product *product = [[Product alloc] init];
	
	Money totalPrice1 = [product getPriceFor:MakeQuantityFromPieces(10)];
	Money totalPrice2 = [product getPriceFor:MakeQuantityFromPieces(20)];
	Money expected = MakeMoney(0, 0);
	STAssertEquals(totalPrice1, expected, @"Expected $0.00 for empty product, but was %@", FormatMoney(totalPrice1));
	STAssertEquals(totalPrice2, expected, @"Expected $0.00 for empty product, but was %@", FormatMoney(totalPrice2));
}

- (void)testProductCreateSimplePrice {
	id price = [[SimplePricing alloc] initWithPrice:MakeMoney(9, 99)];
	Product *product = [[Product alloc] initWithCode:@"TEST" andPrice:price];
	
	Quantity quantity0 = MakeQuantityFromPieces(0);
	Quantity quantity1 = MakeQuantityFromPieces(1);
	Quantity quantity55 = MakeQuantityFromPounds(5.5);
	Money priceFor0 = [product getPriceFor:quantity0];
	Money priceFor1 = [product getPriceFor:quantity1];
	Money priceFor55 = [product getPriceFor:quantity55];
	
	STAssertEquals(priceFor0, MakeMoney(0, 0), @"Expected $0.0 for 0 pieces, but was %@", FormatMoney(priceFor0));
	STAssertEquals(priceFor1, MakeMoney(9, 99), @"Expected $9.99 for 1 piece, but was %@", FormatMoney(priceFor1));
	STAssertEquals(priceFor55, MakeMoney(54, 95), @"Expected $54.95 for 5.5 pounds, but was %@", FormatMoney(priceFor55));
}

- (void)testProductCreateAdditionalFreeItemsPricePieces {
	id price = [[AdditionalFreeItemsPricing alloc] initWithPrice:MakeMoney(9, 99) paidQuantity:MakeQuantityFromPieces(2) freeQuantity:MakeQuantityFromPieces(1) ];
	Product *product = [[Product alloc] initWithCode:@"TEST" andPrice:price];
	
	Quantity quantity0 = MakeQuantityFromPieces(0);
	Quantity quantity1 = MakeQuantityFromPieces(1);
	Quantity quantity4 = MakeQuantityFromPieces(4);
	Money priceFor0 = [product getPriceFor:quantity0];
	Money priceFor1 = [product getPriceFor:quantity1];
	Money priceFor4 = [product getPriceFor:quantity4];
	
	STAssertEquals(priceFor0, MakeMoney(0, 0), @"Expected $0.0 for 0 pieces, but was %@", FormatMoney(priceFor0));
	STAssertEquals(priceFor1, MakeMoney(9, 99), @"Expected $9.99 for 1 piece, but was %@", FormatMoney(priceFor1));
	STAssertEquals(priceFor4, MakeMoney(29, 97), @"Expected $29.97 for 4 pieces, but was %@", FormatMoney(priceFor4));
}

- (void)testProductCreateAdditionalFreeItemsPricePounds {
	id price = [[AdditionalFreeItemsPricing alloc] initWithPrice:MakeMoney(9, 99) paidQuantity:MakeQuantityFromPounds(3.5) freeQuantity:MakeQuantityFromPounds(1.5) ];
	Product *product = [[Product alloc] initWithCode:@"TEST" andPrice:price];
	
	Quantity quantity0 = MakeQuantityFromPounds(0);
	Quantity quantity15 = MakeQuantityFromPounds(1.5);
	Quantity quantity72 = MakeQuantityFromPounds(7.2);
	Quantity quantity99 = MakeQuantityFromPounds(9.9);
	Money priceFor0 = [product getPriceFor:quantity0];
	Money priceFor15 = [product getPriceFor:quantity15];
	Money priceFor72 = [product getPriceFor:quantity72];
	Money priceFor99 = [product getPriceFor:quantity99];
	
	STAssertEquals(priceFor0, MakeMoney(0, 0), @"Expected $0.0 for 0 pounds, but was %@", FormatMoney(priceFor0));
	STAssertEquals(priceFor15, MakeMoney(14, 99), @"Expected $14.99 for 1.5 pounds, but was %@", FormatMoney(priceFor15));
	STAssertEquals(priceFor72, MakeMoney(56, 95), @"Expected $56.95 for 7.2 pounds, but was %@", FormatMoney(priceFor72));
	STAssertEquals(priceFor99, MakeMoney(69, 93), @"Expected $69.93 for 9.9 pounds, but was %@", FormatMoney(priceFor99));
}


@end
